package com.bookstore.MapperDao;

import com.bookstore.bean.Trade;
import utils.MybatisSessionFactory;

import java.util.*;

/**
 * Created by Admin on 2016/8/12.
 */
public class TradeMapImp implements TradeMap{
    private String str = "com.bookstore.mapper.TradeMapper.";

    /**
     * 向数据表中插入Trade 对象,并返回新增的id 的值;
     *
    * @param trade
    */
    public int insert(Trade trade) {
        String statement = str + "insert";
        MybatisSessionFactory.getSession().insert(statement,trade);
        int id=trade.getTradeId();
        return id;
    }


    /**
     * 根据userId 获取和其相关联的Trade 的集合
     *
     * @param userId
     * @return
     */
    public List<Trade> getTradesWithUserId(Integer userId) {
        String statement = str + "getTradesWithUserId";
        List<Trade> trades = new ArrayList<>(MybatisSessionFactory.getSession().selectList(statement, userId));
        return trades;
    }
}
